package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.constant.StatusConstant;
import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@Slf4j
@RequestMapping("/admin/shop")
@RestController
///admin/shop/status
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/status")
    public Result getStatus() {
        ValueOperations vo = redisTemplate.opsForValue();
        Integer shopStatus = (Integer) vo.get("SHOP_STATUS");
        return Result.success(shopStatus);
    }

    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status) {
        log.info("设置店铺状态：{}", Objects.equals(status, StatusConstant.ENABLE) ? "营业中" : "打烊中");
        ValueOperations vo = redisTemplate.opsForValue();
        vo.set("SHOP_STATUS", status);
        return Result.success();
    }

}
